Repository navigation
Match PR Files changed diff order to the file tree - #9488
davkim1030 wants to merge 3 commits into
Conversation
The desktop GitHub PR "Files changed" view rendered the file tree in source-control DFS order (directories first, then path-sorted files) but rendered the diff sections below in raw GitHub API order. The two orders diverged, so a file clicked in the tree was hard to locate in the diff scroll. Order the diff-section entries through the same tree the file list is built from, so both views share one ordering — matching GitHub's web behavior. Adds collectSourceControlTreeFileEntriesInOrder to reuse the tree's leaf DFS order for the flat section list, plus a regression test asserting the flat order equals the flattened tree file rows. Mobile is unaffected: mobile-diff-review-queue already sorts list and detail from a single localeCompare source, so no divergence exists there. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Strengthen the ordering regression test: compare the diff-section order (collectSourceControlTreeFileEntriesInOrder) against the file tree's actual render path (compactSourceControlTree + flattenSourceControlTree, matching CombinedDiffFileTree.buildBranchRows), instead of comparing two functions that share the same traversal. Also covers that compaction preserves leaf order. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Document the new tree-ordering helper with a JSDoc block (params, return, and the list/diff-sync rationale) so the exported API is self-describing. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
Caution Review failedAn error occurred during the review process. Please try again later. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Needs a rebase — this branch now conflicts with Not resolving it here: Verified green against the branch's own merge base — details in the PR description. Also note the failing |
Superseded by #10081 — recommend closingThe bug is fixed on main. Commit I verified main's implementation: Main's approach is also closer to the truth: it orders via Also worth recording, since it may confuse anyone revisiting this: the failing The branch is conflicting against main. Recommending close as superseded — the diagnosis was right, and #10081 shipped the same fix with wider coverage. |
|
@nwpark Thanks for the comments |
Summary
The PR "Files changed" diff sections were ordered by the raw API response (
files.map(gitHubPRFileToBranchEntry)), while the file tree beside them renders in source-control order — depth-first, directories before files, path-sorted within each level. Scrolling the list and scrolling the diff therefore disagreed.This derives the section order from the same tree the list renders, via a new
collectSourceControlTreeFileEntriesInOrder()export, rather than reimplementing a parallel sort that would drift.ELI5
The Files-changed page has a list of files on one side and the actual diffs on the other. The list was sorted one way and the diffs another, so clicking or scrolling one didn't line up with the other. Now both come from the same source, so they always agree.
Proof of fix
With
source-control-tree.tsrestored from the branch's merge base:With this PR:
Proof of no regressions
The sidebar tree order is unchanged. This was the main regression risk, since
source-control-tree.tsis shared: a change to its comparator would silently reorder the source-control sidebar for everyone. Verified the diff adds an export and touches no existing comparator —git diff … | grep -E '^[-+].*(localeCompare|sort|compare)'returns nothing but the new doc comment.User-visible behavior that changes:
source-control-tree.tsare untouched.Compatibility
AGENTS.md): checked, sincePullRequestPagealso serves GitLab, Gitea, and Bitbucket. The new function takesSourceControlTreeEntryvalues built fromgitHubPRFileToBranchEntry, which normalizes provider payloads to a common shape before the tree is built — no GitHub-only field is referenced in the ordering path.entriesCacheRefsignature guard, so it runs only whendiffEntrySignaturechanges, not on every render. For a 1000-file PR this is oneO(n log n)pass per file-set change rather than per paint.Screenshots
The change is an ordering difference between two panes — a static screenshot of a correctly-ordered list is indistinguishable from an incorrectly-ordered one without knowing the expected order, so an image would not evidence the fix. The guarantee is instead pinned by a test asserting the emitted order matches the rendered tree. I did not capture before/after images; stating that plainly rather than implying a visual check I didn't perform.
Testing
pnpm lint— not run in full. Rannpx oxlint --config config/oxlint-react-doctor.jsonon the changed component: 5 warnings, identical count on the merge base, so nothing introduced here.pnpm typecheck—npx tsc --noEmit -p config/tsconfig.tc.web.json, exit 0.pnpm test— not run in full (30+ min). Ran the touched module's suite: 10 tests passed.pnpm build— not run.On the failing
track-community-prcheckNot a code failure. The job is org bookkeeping — it calls
GET /orgs/stablyai/teams/stably-eng/memberships/davkim1030to classify the author as internal or community, and errors because the author is not a member of that team, which is the expected state for a community contributor. It does not build, lint, or test anything in this PR. No action needed from the author.AI Review Report
Reviewed with Claude Code (Opus 5). Risks checked:
buildSourceControlTreerather than a second comparator.source-control-tree.tsbacks the source-control sidebar. Confirmed no existing comparator or sort call was modified, so sidebar ordering is byte-identical.a.path.localeCompare(b.path, undefined, { numeric: true }), andundefinedmeans "use the runtime's locale", which genuinely diverges: sorting['a.ts','ab.ts','ä.ts','z.ts']putsä.tsbeforeab.tsunder the default and afterz.tsundersv-SE. This is pre-existing onmain, not introduced here (verified viagit show origin/main:…), and this PR makes the two panes consistently locale-ordered rather than inconsistently ordered — a strict improvement. Flagged as a follow-up below rather than silently expanded.diffEntrySignaturecache guard, so it is not re-run per render.Security Audit
Notes
compareEntriespassesundefinedas thelocaleComparelocale, so file ordering varies with the user's system locale — two developers on the same PR can see different orders, and it makes ordering assertions locale-fragile. Pinning an explicit locale (or using a codepoint comparator) would make it deterministic. Deliberately not changed here, because it would alter the source-control sidebar ordering for every user and belongs in its own PR.main; a rebase is advisable before merge, though nothing in the diff conflicts.Original patch by @davkim1030.